<?php

namespace App\Service\Message\v1_1_2;

use App\Constants\ErrorCode;
use App\Model\UserAutoMsg;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 自动聊天消息设置提交
 */
class AutoMsgSubmitService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $msgType = $this->request->input('msg_type', 'text');
        $msgContent = $this->request->input('msg_content', '');
        $duration = $this->request->input('duration', 0);
        $voiceTag = $this->request->input('voice_tag', '');

        if (!UserProfile::checkAvatarVrfied($userId)) {
            return $this->setError(ErrorCode::REAL_AVATAR_NOT_VRFY, '非真人认证暂无法设置自动打招呼消息~');
        }

        $checkNum = UserAutoMsg::getMsgTypeNum($userId, $msgType);
        if ($checkNum >= 10) {
            return $this->setError(ErrorCode::AUTO_MSG_LMT, '消息保存超过数量限制~');
        }
        $result = UserAutoMsg::addRecord($userId, $msgType, $msgContent, $duration,$voiceTag);
        $ret = [
            'record_id' => 1,
            'msg_type' => $msgType,
            'msg_content' => UserAutoMsg::getUserTypeMsgs($userId, $msgType),
            // 'status' => UserAutoMsg::getStatus(UserAutoMsg::STATUS_ING)
        ];
        return $ret;
    }
}
